<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-table :data="powerList.perms" border style="width: 100%">
        <el-table-column type="index" label="序号">
        </el-table-column>
        <el-table-column prop="authName" label="权限名称">
        </el-table-column>
        <el-table-column prop="path" label="路径">
        </el-table-column>
        <el-table-column prop="level" label="等级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level === '0'">一级</el-tag>
            <el-tag type="success" v-else-if="scope.row.level === '1'">二级</el-tag>
            <el-tag type="warning" v-else>三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum"
            :page-sizes="[5, 10]"
            :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        powerList: [],
        queryInfo: {
          pagenum: 1,
          pagesize: 5
        },
        total: null
      }
    },
    methods: {
      async getAllPower() {
        let {data: res} = await this.$http.get('/permission/rights/list',{
          params: this.queryInfo
        })
        if(res.meta.status !==200 ) return this.$message.error('权限列表获取失败');
        this.powerList = res.data;
        this.total = res.data.total;
        console.log(res)
      },
      handleSizeChange(newSize) {
        this.queryInfo.pagesize = newSize;
        this.getAllPower();
      },
      handleCurrentChange(newPage) {
        this.queryInfo.pagenum = newPage;
        this.getAllPower();
      },
    },
    created() {
      this.getAllPower();
      
    }
  }
</script>

<style>
  
</style>
